package online.longzipeng.mywebdemo.config;

import lombok.extern.slf4j.Slf4j;
import online.longzipeng.mywebdemo.mapper.BookSensitiveWordMapper;
import online.longzipeng.mywebdemo.utils.SensitiveWordUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @Author: lzp
 * @description: 项目初始化后执行对应操作 可在项目启动时传递参数 java -jar demo.jar arg1 arg2 arg3
 * @Date: 2023/10/30
 *
 */
@Component
@Slf4j
public class ApplicationInitConfig implements CommandLineRunner {
	@Autowired
	private BookSensitiveWordMapper bookSensitiveWordMapper;

	@Override
	public void run(String... args) {
		// 初始化敏感词
		this.initSensitiveWordUtil();
	}

	/**
	 * 初始化敏感词工具类的字典
	 */
	private void initSensitiveWordUtil() {
		log.info("===初始化敏感词字典==");
		Set<String> words = bookSensitiveWordMapper.listAllWords();
		SensitiveWordUtil.init(words);
		log.info("===敏感词字典初始化完毕，共{}个词汇==", words.size());
	}

}